Require a PREFIX when deleting refs
authorMatthew Barnes <mbarnes@redhat.com>
Tue, 6 Jan 2015 14:36:45 +0000 (09:36 -0500)
committerMatthew Barnes <mbarnes@redhat.com>
Tue, 6 Jan 2015 15:33:12 +0000 (10:33 -0500)
Also fix the "ostree refs" help output to not give the impression that
the --delete option takes its own PREFIX argument.

https://bugzilla.gnome.org/show_bug.cgi?id=742454

src/ostree/ot-builtin-refs.c
tests/basic-test.sh

index 10dcc7215b9c0158e3d5cdebae2e092b5e890608..9b02ca95615a2fe607b0b0fa582f096c8d393156 100644 (file)
@@ -30,7 +30,7 @@
 static gboolean opt_delete;
 
 static GOptionEntry options[] = {
-  { "delete", 0, 0, G_OPTION_ARG_NONE, &opt_delete, "Delete refs which match PREFIX, rather than listing them", "PREFIX" },
+  { "delete", 0, 0, G_OPTION_ARG_NONE, &opt_delete, "Delete refs which match PREFIX, rather than listing them", NULL },
   { NULL }
 };
 
@@ -53,6 +53,14 @@ ostree_builtin_refs (int argc, char **argv, GCancellable *cancellable, GError **
   if (argc >= 2)
     refspec_prefix = argv[1];
 
+  /* Require a prefix when deleting to help avoid accidents. */
+  if (opt_delete && refspec_prefix == NULL)
+    {
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                   "PREFIX is required when deleting refs");
+      goto out;
+    }
+
   if (!ostree_repo_list_refs (repo, refspec_prefix, &refs,
                               cancellable, error))
     goto out;
index d097a320c51a992df7a67e1d1117ce8b4bcdca8f..106d9f120d2fd57d08f4754d3bab863c279d83c9 100755 (executable)
@@ -45,6 +45,8 @@ $OSTREE refs > reflist
 assert_file_has_content reflist '^test2$'
 rm reflist
 
+$OSTREE refs --delete 2>/dev/null && (echo 1>&2 "refs --delete (without prefix) unexpectedly succeeded!"; exit 1)
+
 echo "ok refs"
 
 cd checkout-test2